#!/usr/bin/lua
require("lua-xwrt.addon.string")
require("lua-xwrt.addon.uci")
general = { 
	"context",
	"allowguest",
	"allowoverlap",
	"allowtransfer",
	"realm",
	"bindport",
	"bindaddr",
	"srvlookup",
	"pedantic",
	"tos_sip",
	"tos_audio",
	"tos_video",
	"maxexpiry",
	"minexpiry",
	"defaultexpiry",
	"t1min",
	"notifymimetype",
	"checkmwi",
	"buggymwi",
	"vmexten",
	"disallow",
	"allow",
	"mohinterpret",
	"mohsuggest",
	"language",
	"relaxdtmf",
	"trustrpid",
	"sendrpid",
	"progressinband",
	"useragent",
	"promiscredir",
	"usereqphone",
	"dtmfmode",
	"compactheaders",
	"videosupport",
	"maxcallbitrate",
	"callevents",
	"alwaysauthreject",
	"g726nonstandard",
	"matchexterniplocally",
	"dynamic_exclude_static",
	"contactdeny",
	"contactpermit",
	"regcontext",
	"rtptimeout",
	"rtpholdtimeout",
	"rtpkeepalive",
	"sipdebug",
	"recordhistory",
	"dumphistory",
	"allowsubscribe",
	"subscribecontext",
	"notifyringing",
	"notifyhold",
	"limitonpeers",
	"t38pt_udptl",
	"register",
	"registertimeout",
	"registerattempts",
	"externip",
	"externhost",
	"externrefresh",
	"localnet",
	"nat",
	"canreinvite",
	"directrtpsetup",
	"canreinvite",
	"canreinvite",
	"rtcachefriends",
	"rtsavesysname",
	"rtupdate",
	"rtautoclear",
	"ignoreregexpire",
	"domain",
	"allowexternaldomains",
	"autodomain",
	"fromdomain",
	"jbenable",
	"jbforce",
	"jbmaxsize",
	"jbresyncthreshold",
	"jbimpl",
	"jblog"
	}
	
user = {
		"context",
		"callingpres",
		"deny",
		"permit",
		"secret",
		"md5secret",
		"dtmfmode",
		"canreinvite",
		"nat",
		"callgroup",
		"pickupgroup",
		"language",
		"disallow",
		"allow",
		"insecure",
		"trustrpid",
		"progressinband",
		"promiscredir",
		"useclientcode",
		"accountcode",
		"setvar",
		"callerid",
		"amaflags",
		"call-limit",
		"allowoverlap",
		"allowsubscribe",
		"allowtransfer",
		"subscribecontext",
		"videosupport",
		"maxcallbitrate",

		"rfc2833compensate",
		"t38pt_usertpsource"
}

peer = {	
		"context",
		"callingpres",
		"deny",
		"permit",
		"secret",
		"md5secret",
		"dtmfmode",
		"canreinvite",
		"nat",
		"callgroup",
		"pickupgroup",
		"language",
		"disallow",
		"allow",
		"insecure",
		"trustrpid",
		"progressinband",
		"promiscredir",
		"useclientcode",
		"accountcode",
		"setvar",
		"callerid",
		"amaflags",
		"call-limit",
		"allowoverlap",
		"allowsubscribe",
		"allowtransfer",
		"subscribecontext",
		"videosupport",
		"maxcallbitrate",

		"mailbox",
		"username",
		"template",
		"fromdomain",
		"regexten",
		"fromuser",
		"host",
		"port",
		"qualify",
		"defaultip",
		"rtptimeout",
		"rtpholdtimeout",
		"sendrpid",
		"outboundproxy",

		"rfc2833compensate",
		"t38pt_usertpsource",

		"contactpermit",
		"contactdeny"
}

sip = io.open("/etc/asterisk/"..arg[1])
for line in sip:lines() do
	local comment = string.find(line,';') or 0
--	line = string.sub(line,1,comment-1)
	line = string.trim(line)
	local first = string.sub(line,1,1)
	local starSection = false
	if string.match(line,"%[") then
		starSection = true
	end
	comment = string.find(line,";")
	if comment then
		line = string.sub(line,1,comment-1)
	end
	if line ~= ""
	then
		if starSection then
			print(line)
		else
			print("",line)
		end
	end
end
sip:close()

--[[
sip = uci.get_all("sip")
for k, v in pairs(sip) do
	print(k)
	for i, d in pairs(v) do
		print("",i,d)
	end
end
]]